﻿using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;

namespace Jinndev {

    public class MouseClick : MonoBehaviour, IPointerClickHandler {

        [Serializable]
        public class PointerClickedEvent : UnityEvent<Vector2> { }

        public PointerClickedEvent onLeftClick = new PointerClickedEvent();
        
        public PointerClickedEvent onRightClick = new PointerClickedEvent();

        public PointerClickedEvent onMiddleClick = new PointerClickedEvent();


        public void OnPointerClick(PointerEventData eventData) {
            if (eventData.button == PointerEventData.InputButton.Left) {
                onLeftClick?.Invoke(eventData.position);
            }
            else if (eventData.button == PointerEventData.InputButton.Right) {
                onRightClick?.Invoke(eventData.position);
            }
            else if (eventData.button == PointerEventData.InputButton.Middle) {
                onMiddleClick?.Invoke(eventData.position);
            }
        }

    }

}